(:
   Conversion of a display file to HTML
 :)
import module namespace
    jj = "http://kumquat.emse.fr/utilitaires"
    at "jjutils.xq" ;

declare variable $elts := doc($arguments[1])/display/item;
declare variable $nums :=
   if (fn:empty($elts/info[@name="num"]))
   then
     for $i at $p in $elts return $p
   else
     for $i at $p in $elts return
        if ($i/info[@name="num"])
        then $i/info[@name="num"]/text() 
        else ""    ;
<html>
<head>
  <title>Display file : {$arguments[1]}</title>
</head>
<body>
<h1>Display file : {$arguments[1]}</h1>
<table>
  { for $e at $p in $elts
    let $d := jj:dateFromDREW(jj:get-item-info($e,"time")/date[1])
    return
       (
       <tr>{
         <td>{ $nums[$p] }</td>,
         <td>{
             if ($e/info[@name="defaultbgcolor"]/color/text())
             then
                <font>{
                    attribute color { string($e/info[@name="defaultbgcolor"]/color/text()) } ,
                $d}</font>
             else
               $d
         }</td>,
         <td>{
             if (string($e/info[@name="defaultbgcolor"]/color/text()) = "lightred")
             then  
                 <img src="icon-warning.png"/>
             else
                 ()
         }</td>,
         <td><img src="{ concat('icon-',string(jj:get-item-info($e,"type")), '.png') }"/></td>,
         <td>{ string(jj:get-item-info($e,"user")) }</td>,
         <td>{ string(jj:get-item-info($e,"chat-tag")) }</td>,
         <td>{ 
            (for $s in $e/info/text| $e/info/html | $e/info/img
             return
             if ($s/self::text) then
                <font>{$s/@color, $s/text()}</font>
             else
             if ($s/self::html | $s/self::img) then
                $s/node()
             else
                ())
        }</td>
      }</tr>
      )
  }
</table>
</body>
</html>

